package com.hex.ds.hdtp.core.inf.sdm.repository.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.sdm.mapper.ISdmConvertTaskMapper;
import com.hex.ds.hdtp.core.inf.sdm.po.SdmConvertTaskPo;
import com.hex.ds.hdtp.core.inf.sdm.repository.ISdmConvertTaskRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SdmConvertTaskRepository implements ISdmConvertTaskRepository {

    private final ISdmConvertTaskMapper  sdmConvertTaskMapper;
    private final IPageAndMyBatisPlusPageConverter pageConverter;

    @Override
    public SdmConvertTaskPo queryById(String pkId) {
        return sdmConvertTaskMapper.selectById(pkId);
    }

    @Override
    public Integer add(SdmConvertTaskPo sdmConvertTaskPo) {
        return sdmConvertTaskMapper.insert(sdmConvertTaskPo);
    }

    @Override
    public Integer modifyById(SdmConvertTaskPo sdmConvertTaskPo) {
        return sdmConvertTaskMapper.updateById(sdmConvertTaskPo);
    }

    @Override
    public Integer removeById(String pkId) {
        return sdmConvertTaskMapper.deleteById(pkId);
    }

    @Override
    public Page<SdmConvertTaskPo> queryListByPage(SdmConvertTaskPo sdmConvertTaskPo, Page page) {
        final IPage tmpPageResult = sdmConvertTaskMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(page)
                , sdmConvertTaskPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }
}
